package com.buer.storage.controller;

import com.buer.storage.commom.JsonResult;
import com.buer.storage.dto.*;
import com.buer.storage.entity.Worder;
import com.buer.storage.service.WorderService;
import com.buer.storage.vo.R;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/put")
public class WorderController {
    @Resource
    private WorderService worderService;

    //增加入库信息
    @PostMapping("/insertPutStorage.do")
    public R insert(@RequestBody PutStorageDto putStorageDto){
       // System.out.println(putStorageDto);
        if (worderService.insert(putStorageDto) > 0) {

            return R.setR(1, "入库单保存成功", null);
        }

        return R.setR(0,"入库单保存失败",null);
    }

    //查询所有订单信息
    @GetMapping("/findOrderAll.do")
    public List<WorderDto> findOrderAll(){
        List<WorderDto> orderAll = worderService.findOrderAll();
        return orderAll;
    }

    @PostMapping("/selectByAll.do")
    public JsonResult selectByAll(@RequestBody Map<String,Object> params){
        PageInfo<Worder> entityList = worderService.selectByAll(params);
        Map result=new HashMap<>();
        result.put("total",entityList.getTotal());
        result.put("list",entityList.getList());
        return new JsonResult(1,result);
    }


    //根据入库订单ID删除入库信息
    @GetMapping("/deletePutStorageById.do")
    public R deletePutStorageById(int putId) {
        if (worderService.deletePutStorageById(putId) > 0) {
            return R.setR(1, "删除入库单成功", null);
        }
        return R.setR(0, "删除入库单失败", null);
    }

    //根据商品ID删除商品信息
    @GetMapping("/deleteWorderdetails.do")
    public R deleteWorderdetails(int detailsId) {
        if (worderService.deleteWorderdetails(detailsId) > 0) {
            return R.setR(1, "删除入库单成功", null);
        }
        return R.setR(0, "删除入库单失败", null);
    }

    //更新ID删除商品信息
    @PostMapping("/updateWorderdetails.do")
    public R updateWorderdetails(@RequestBody PutStorageDto putStorageDto) {
        if (worderService.updateWorderdetails(putStorageDto) > 0) {
            return R.setR(1, "更新入库单成功", null);
        }
        return R.setR(0, "更新入库单失败", null);
    }

    //提交商品详情进行累加
        @GetMapping("/submitAddWorderdetails.do")
        public R submitAddBuerStock(Integer putId) {
        if (worderService.submitAddBuerStock(putId) > 0) {
            return R.setR(1, "入库存成功", null);
        }
        return R.setR(0, "入库存失败", null);
    }

    //根据订单ID查询入库信息
    @GetMapping("/findPutAll.do")
    public List<PutStorageAllDto> findPutAll(Integer putId){
        List<PutStorageAllDto> putAll = worderService.findPutAll(putId);
        return putAll;
    }

    @PostMapping("/getWord")
    public JsonResult getWord(@RequestBody Map<String,Object> params) {
        PageInfo<WorderDto> entityList = worderService.getWord(params);
        Map result=new HashMap<>();
        result.put("total",entityList.getTotal());
        result.put("list",entityList.getList());
        return new JsonResult(1,result);
    }

    @PostMapping("/getWorderdetails")
    public JsonResult getWorderdetails(@RequestBody Map<String,Object> params) {
        PageInfo<WorderdetailsDto> entityList = worderService.getWorderdetails(params);
        Map result=new HashMap<>();
        result.put("total",entityList.getTotal());
        result.put("list",entityList.getList());
        return new JsonResult(1,result);
    }

    @PostMapping("/getStock")
    public JsonResult getStock(@RequestBody Map<String,Object> params) {
        PageInfo<StockDto> entityList = worderService.getStock(params);
        Map result=new HashMap<>();
        result.put("total",entityList.getTotal());
        result.put("list",entityList.getList());
        return new JsonResult(1,result);
    }
}
